package com.thinvent.recommend.common.enums;

/**
 * 文件操作类型枚举，对应数据库表 t_kb_file_history 中的 ACTION_TYPE 字段。
 */
public enum FileHistoryActionTypeEnums {

    UPLOAD("0", "上传"),
    EDIT("1", "编辑"),
    PREVIEW("2", "预览"),
    DOWNLOAD("3", "下载"),
    MOVE("4", "移动"),
    COPY("5", "拷贝"),
    DELETE("6", "删除"),
    SHARE("7", "分享"),
    FORWARD("8", "转发"),
    LIKE("9", "点赞"),
    FAVORITES("10", "收藏");

    private final String code;

    private final String description;

    FileHistoryActionTypeEnums(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /** 返回枚举对应的数据库存储值 */
    public String getCode() {
        return code;
    }

    /** 返回枚举的中文描述 */
    public String getDescription() {
        return description;
    }

    /**
     * 根据 code 值获取枚举实例
     * @param code 数据库中的 ACTION_TYPE 值
     * @return 对应的 FileHistoryActionType，找不到时抛 IllegalArgumentException
     */
    public static FileHistoryActionTypeEnums fromCode(String code) {
        for (FileHistoryActionTypeEnums type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown FileHistoryActionType code: " + code);
    }

    @Override
    public String toString() {
        return code + " - " + description;
    }
}
